﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HammerMUD.Commands;
using HammerMUD.Areas;
using HammerMUD.Rooms;
using HammerMUD.System;

namespace HammerMUD.Admin
{
    public class MakeAreaCommand : Command
    {
        public MakeAreaCommand()
        {
            Name = "makearea";
            Help = "makearea <area name> [<area size> = 500]";
            SecurityLevel = SecurityLevel.Admin;
        }

        public override void Do(HammerMUD.System.User from, List<string> arguments)
        {
            Int64 numberOfRooms = 500;
            Int64 startingRoom = 1;
            Area newArea = new Area();

            if (arguments.Count == 1)
            {
                from.Send(Help);
                from.UserAccount.StandardPrompt();
                return;
            }

            if (arguments.Count > 2)
            {
                numberOfRooms = Int64.Parse(arguments[2]);
            }

            foreach (Area a in HammerMUD.System.HammerMUD.Areas)
            {
                Int64 areasMax = a.Rooms.Last().RoomNumber;
                if (areasMax > startingRoom)
                {
                    startingRoom = areasMax;
                }
            }

            newArea.Name = arguments[1];
            newArea.Rooms = new List<Room>();
            for (long i = startingRoom; i < startingRoom + numberOfRooms; i++)
            {
                newArea.Rooms.Add(new Room() { Name = "Blank Room!", RoomNumber = i, MemberOfArea = newArea });
            }

            HammerMUD.System.HammerMUD.Areas.Add(newArea);
            SystemUtilities.SaveAreas(HammerMUD.System.HammerMUD.Areas);
        }
    }
}
